import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import localhost.axis.services.Admin_Users.AdminServiceLocator;


public class Userbean {
	
	private String username;
	private String password;
	private Message[] messages = {new Message("Please validate UV")};

	
	private boolean addUV = false;
	
	public boolean isAddUV() {
		if (username.equals("Exposito")){
			addUV = true;
		} else {
			addUV = false;
		}
		return addUV;
	}
	public void setAddUV(boolean addUV) {
		this.addUV = addUV;
	}
	public Message[] getMessages() {
		return messages;
	}
	public void setMessages(Message[] messages) {
		this.messages = messages;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String login(){
		AdminServiceLocator admin = new AdminServiceLocator();
		boolean res = false;
		try {
			res = admin.getAdmin_Users().connect(username, password);
			System.out.println("Login : " + this.username + " - " + this.password);
		} catch (Exception e) {
    		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( FacesMessage.SEVERITY_INFO, "Invalid username or password", "Invalid username or password"));
    		return "fail";
		}
		if (res){
			return "ok";
		} else {
    		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( FacesMessage.SEVERITY_INFO, "Invalid username or password", "Invalid username or password"));
    		return "fail";
		}

	}

	
	

}
